<div class="pull-left" style="margin: 10px;">
    <div class="box-filter">
        <form id="task_search_form">
            <label>查找:</label>
            <input type="text" name="end" class="date" placeholder="结束日期" value="{$end}">--
            <input type="text" name="start" class="date" placeholder="开始日期" value="{$start}">

            <button class="btn btn-success " id="btnSearch">查询</button>
        </form>
    </div>
</div>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-danger">
                <div class="box-body ">
                    <table id="table2" class="table table-bordered table-striped" width="100%">
                        <thead>
                        <tr>
                            <th>选择</th>
                            <th>姓名</th>
                            <th>手机号</th>
                            <th>车号</th>
                            <th>载重</th>
                            <th>塔吊</th>
                            <th>泵送</th>
                            <th>直卸</th>
                            <th>斗卸</th>
                            <th>车数</th>
                            <th>累积时间</th>
                            <th>到站时间</th>
                            <th>状态</th>
                        </tr>
                        </thead>
                        <tbody id="dataBody"></tbody>
                    </table>
                    <div class="box-footer">
                           <span class="input-group-btn">
                                <button class="btn btn-primary pull-right" type="button" id='form_submit2'>提交</button>
                            </span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<script type="text/javascript">
    $('.date').datepicker({language:'zh-CN','autoclose':true});
    var columns = [
        {"data": "id","orderable":false},
        {"data": "name","orderable":false},
        {"data": "mobile","orderable":false},
        {"data": "carno","orderable":false},
        {"data": "load","orderable":false},
        {"data": "tadiao","orderable":false},
        {"data": "bengsong","orderable":false},
        {"data": "zhixie","orderable":false},
        {"data": "douxie","orderable":false},
        {"data": "number","orderable":false},
        {"data": "total_time","orderable":false},
        {"data": "finish_time","orderable":false},
        {"data": "online","orderable":false},
    ];
    var columnDefs = [
        {
            "targets": 0,
            "render": function (data, type, row) {
                return "<input type='radio' value='"+data+"' class='carid' name='sel' carname='"+row.name+"'  carno='"+row.carno+"'/>";
            }
        },
        {
            "targets": 4,
            "render": function (data, type, row) {
                return data+"方";
            }
        },
        {
            "targets": 10,
            "render": function (data, type, row) {
                var t =  data>0?data:0;
                return t+'分钟';
            }
        },
        {
            "targets": 12,
            "render": function (data, type, row) {
                var now =  "{:time()}";
                var status ="";
                if(row.dis>10000){
                    status+="&gt;10km";
                }else if(row.dis>1000){
                    status+=""+(row.dis/1000).toFixed(2)+"km";
                }else{
                    status+="&lt;0.5km";
                }
                if(data>now-3600){
                    status+="<br/><span style='color:green;'>在线</span>";
                }else{
                    status += '<br/><span style="color:red;">离线</span>';
                }
                return status;
            }
        }
    ];
    $('#form_submit2').click(function () {
        if($(".carid:checked").length==0){
            $.messager.alert('提示信息', '请选择车辆,如果没有车辆请稍后再试', 'error');
            return;
        }
        var car  = $(".carid:checked").val();
        var carname = $(".carid:checked").attr('carname');
        var carno = $(".carid:checked").attr('carno');
        $("#car_id").val(car);
        $("#def_carname").val(carname+"    车号:"+carno);
        dialog.get('onlinecar').close().remove();
    });
    var task_dataTable;
    $(function () {
        task_dataTable = $('#table2').dataTable({
            "autoWidth": false,
            "processing": true, //载入数据的时候是否显示“载入中”
             ordering: false, //排序操作在服务端进行，所以可以关了。
            'serverSide': true,
            'searching':false,
            'lengthChange':false,
            'pageLength':6,
            "ajax":{
                "url": "{:U('Task/getCar','load='.$load.'&roadsid='.$roadsid)}",
                "type": "POST"
            },
            "columns": columns,
            "columnDefs":columnDefs ,
            "language": lang
        });
    });

    $('#btnSearch').click(function(){
        var api = task_dataTable.api();
        var data = $("#task_search_form").serialize()
//            alert("{:U('Finance/cash')}?"+data);
//            cash_dataTable.settings()[0].ajax.data = data;
        api.ajax.url("{:U('Task/getCar','load='.$load.'&roadsid='.$roadsid)}?"+data);
        api.ajax.reload();
        return false;
    });


</script>

